package com.example.demo.dao.Impl;

import com.example.demo.dao.IUserDao;
import com.example.demo.pojo.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings({"all"})
@Repository
public class UserDaoImpl implements IUserDao {

    private List<User> users = new ArrayList<>();

    public UserDaoImpl() {
        super();
        users.add(new User(1, "user_name_1"));
        users.add(new User(2, "user_name_2"));
        users.add(new User(3, "user_name_3"));
    }

    @Override
    public User getUser(Integer id) {
        for (User user : users) {
            if (user.getId() == id) {
                return user;
            }
        }
        return null;
    }

    @Override
    public Boolean insertUser(User user) {
        Boolean flag = false;
        System.out.println(user.getUserName());
        users.add(user);
        flag = true;
        return flag;
    }

    @Override
    public List<User> findAllUser() {
        return users;
    }
}
